var app = angular.module('businessApp', []);


app.controller('businessController', function($scope, $http, BusinessService) {
	$scope.load=function(){
		$scope.sel=$scope.sel?$scope.sel:{};
		var pageNum=$scope.pageInfo?$scope.pageInfo.pageNum:1;
		var pageSize=$scope.pageInfo?$scope.pageInfo.pageSize:10;
		$scope.sel.pageNum=pageNum;
		$scope.sel.pageSize=pageSize;
		BusinessService.list($scope.sel).success(function (response) {
			$scope.pageInfo=response.data;
			$scope.pageInfo.pageLinks=getPageLinks(response.data.pageNum,response.data.pages);
		});
	
	}
	
	$scope.load();
    $scope=pagination.init($scope);
    $scope.businessCreator=function(){
    	document.location.href='manage/business/add.jsp';
    }
    $scope.refreshData=function(){
    	$scope.load();
    }
   /* $scope.lock=function(id){
    	BusinessService.lock(id).success(function (response) {
    		$scope.load();
    	});
    }*/
    
    $scope.delTip=function(id,mes){
    	$scope.delItem={id:id,mes:mes};
    	$('#box-del').modal({
    		show: true
    	});
    	
    }
    $scope.del=function(id){
    	BusinessService.del(id).success(function (response) {
    		$('#box-del').modal('hide');
    		$scope.load();
    	});
    }
});

app.factory('BusinessService', function ($http) {
	var list = function (param) {
        return $http({
            params: param,
            url: 'qz/business/getByPage'
        });
    };
    var lock = function (id){
    	return $http.put('qz/business/lock/'+id);
    }
    var del = function (id){
    	return $http.put('qz/business/upStatus/'+id);
    }
	return {
		list:function(param){
			return list(param);
		},
		lock:function(id){
			return lock(id);
		},
		del:function(id){
			return del(id);
		}
	}
});
